//
//  MineViewController.m
//  On The Load
//
//  Created by 我爱的妞 on 15/11/5.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "MineViewController.h"
#import <UIImageView+WebCache.h>
#import "XJCMusicCollectViewController.h"
#import "YYMVideoCollectViewController.h"
#import "YYMDownloadViewController.h"

@interface MineViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)UITableView *mineTV;//我的 tableview
@property(nonatomic,retain)UIButton *nightBtn;//夜间模式button

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    _dataArray = [NSArray arrayWithObjects:@"音乐收藏",@"视频收藏", @"夜间模式",@"清除缓存", @"我的下载", nil];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100 * SCALEW, 25 * SCALEH)];
    titleLabel.text = @"我的";
    titleLabel.font = [UIFont fontWithName:@"TimesNewRomanPSMT" size:18];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    [self createViews];
    
}

- (void)createViews{
    self.mineTV = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    self.mineTV.dataSource = self;
    self.mineTV.delegate = self;
    [self.view addSubview:self.mineTV];
    
    UIImageView *headerImgView  = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200 * SCALEH)];
    headerImgView.image = [UIImage imageNamed:@"headerPic.png"];
    self.mineTV.tableHeaderView = headerImgView;
    
}

#pragma mark -- tableview DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    NSString *str = [_dataArray objectAtIndex:indexPath.row];
    
    cell.textLabel.text = str;
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        XJCMusicCollectViewController *vc = [[XJCMusicCollectViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        YYMVideoCollectViewController *vc = [[YYMVideoCollectViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        //夜间
        
        if (self.view.window.alpha == 1) {
            self.view.window.alpha = 0.55;
        }else{
            self.view.window.alpha = 1;
        }
        
    }else if (indexPath.row == 3){
        //缓存
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        float totalSize = size/ 1024.0/1024.0;
        NSLog(@"size = %f",totalSize);

        NSString *message = [NSString stringWithFormat:@"为您删除%fMB",totalSize];
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"清除缓存" message:message preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alterAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            //        清除缓存
            [[SDImageCache sharedImageCache] clearDisk];
            
        }];
        [alertC addAction:alterAction];
       
        [self presentViewController:alertC animated:YES completion:nil];
    }else if (indexPath.row == 4){
        YYMDownloadViewController *vc = [[YYMDownloadViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

@end
